import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/mine'
  },
  {
    path: '/login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
  },
 { path:'/main',
    component:()=>import('../views/Main.vue'),
  
},
{
  path:'/table',
  component:()=>import('../views/table.vue')
},
{
  path:'/mine',
  component:()=>import('../views/mine.vue')
},
{
  path:'/news',
  component:()=>import('../views/news.vue')
},
{
  path:'/clockin',
  component:()=>import('../views/clockIn.vue')
},
{ path:'/grade',
    component:()=>import('../views/grade.vue'),
  
},
{ path:'/feedback',
    component:()=>import('../views/feedback.vue'),
  
}
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if ((!localStorage.getItem('id') || !localStorage.getItem('password'))&&to.path!='/login'){
    router.push('/login')
    Vue.prototype.$msg.fail('请登录!')
    return
  }
  next()
})

export default router
